-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make u32 shift and rotation instructions always checked #1135
Conversation
| u32shl <br> - *(47 cycles)* <br> u32shl.*b* <br> - *(4 cycles)* | [b, a, ...] | [c, ...] | $c \leftarrow (a \cdot 2^b) \mod 2^{32}$ <br> Fails if $a \ge 2^{32}$ or $b > 31$ | | ||
| u32shr <br> - *(47 cycles)*<br> u32shr.*b* <br> - *(4 cycles)* | [b, a, ...] | [c, ...] | $c \leftarrow \lfloor a/2^b \rfloor$ <br> Fails if $a \ge 2^{32}$ or $b > 31$ | | ||
| u32rotl <br> - *(47 cycles)* <br> u32rotl.*b* <br> - *(4 cycles)* | [b, a, ...] | [c, ...] | Computes $c$ by rotating a 32-bit representation of $a$ to the left by $b$ bits. <br> Fails if $a \ge 2^{32}$ or $b > 31$ | | ||
| u32rotr <br> - *(59 cycles)* <br> u32rotr.*b* <br> - *(6 cycles)* | [b, a, ...] | [c, ...] | Computes $c$ by rotating a 32-bit representation of $a$ to the right by $b$ bits. <br> Fails if $a \ge 2^{32}$ or $b > 31$ | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were the previous counts incorrect? Or did this really increase cycle counts for non-immediate operations by 7 - 15 cycles?
Also, would be curious to know how these changes affected things like SHA256 and BLAKE3 computations (we have these in stdlib
- maybe would be a good idea to put together simple examples with them, and then see before/after cycle counts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, these values are not correct. I'm not even sure why were these values like this before. I've updated the functions comments and documentation.
Based on yesterday's discussion, I think we should probably leave the implementation as is (i.e., keep the unchecked implementation). A couple of things we could still do:
|
btw, if you have the code for running blake3 and sha256, would be great to add it to the examples. |
This small PR changes a little bit
u32shl
,u32shr
,u32rotl
andu32totr
instructions to make them always checked — input values are always validated to be a u32 and a value less than 32.